package hlhj.fhp.newslib.network

import android.content.Context
import com.google.gson.Gson
import com.lzy.okgo.model.Response
import hlhj.fhp.newslib.BaseAty
import hlhj.fhp.newslib.javabean.BaseBean
import hlhj.fhp.newslib.utils.ToastUtil
import rx.Observable
import rx.Observer

/**
 * Created by Administrator on 2018\6\27 0027.
 */
abstract class SmartAction<T>(private val context:Context) : Observer<T>{
    override fun onCompleted() {
    }

    override fun onNext(t: T) {
/*        val resp = t as Response<T>
        val json = Gson().toJson(resp.body())
        val baseBean = Gson().fromJson(json, BaseBean::class.java)*/
        /*if (baseBean.code!=null){
            if (baseBean.code==1){
                onResult(t)
            }else{
                onResult(t)
                *//*if (context is BaseAty){
                    context.runOnUiThread {
                        ToastUtil.toast(baseBean.message)
                        context.loadingDialog.dismiss()
                    }
                }*//*
            }
        }*/
    }

    override fun onError(e: Throwable?) {
        e!!.printStackTrace()
//        ToastUtil.toast(e.toString())
    }
    abstract fun onResult(t:T)
}